package gui.admin.tablemodel;

import dao.SaleDao;
import entity.Sale;

import javax.swing.table.DefaultTableModel;
import java.util.List;

public class SaleTableModel extends DefaultTableModel {
    SaleDao saleDao = new SaleDao();
    String[] tableHeaders = new String[]{"订单编号","用户编号","经手人姓名","订单总金额","订单日期"};//订单信息表头
    List saleList = null;
    String[][] saleData = null;
    public SaleTableModel() throws Exception {
        saleList = saleDao.getAllsale();
        saleData = new String[saleList.size()][tableHeaders.length];
        for (int i = 0; i < saleList.size(); i++) {
            Sale sale = (Sale)saleList.get(i);
            saleData[i][0] = sale.getSaleId();
            saleData[i][1] = sale.getUserId();
            saleData[i][2] = sale.getHandlerName();
            saleData[i][3] = String.valueOf(sale.getSaleTotalPrice());
            saleData[i][4] = sale.getSaleDate();
        }
        this.setDataVector(saleData,tableHeaders);
    }
}
